package cn.source.web.controller.oss;

import cn.source.common.core.controller.BaseController;
import cn.source.common.core.domain.AjaxResult;
import cn.source.system.service.FileUploadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * 阿里云oss文件上传 Controller
 *
 * @date 2022-06-19
 */
@RestController
@RequestMapping("/api/oss")
public class FileUploadController extends BaseController {
    @Resource
    private FileUploadService fileUploadService;

    @PostMapping("/upload")
    public AjaxResult upload(@RequestParam("file") MultipartFile uploadFile) {

        try {
            return AjaxResult.success(fileUploadService.upload(uploadFile));
        } catch (Exception e) {
            return AjaxResult.error(e.getMessage());
        }

    }

}
